
<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<h1>View <?php echo $mr2->getMrno() ?></h1>

<div id="sf_admin_content">


<fieldset id="sf_fieldset_none" class="">

<div class="form-row">
  <?php echo label_for('mr2[mrno]', __($labels['mr2{mrno}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{mrno}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{mrno}')): ?>
    <?php echo form_error('mr2{mrno}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <!--Tien code here-->
  <?php $default = CommonValues::GenerateAutoNumber('MR2', $mr2->getMrno(), 'MRSub')   ?>
   <input name="mr2[mrno]" id="mr2_mrno" value="<?php echo $default ?>"  type="hidden">
   <input name="mr2_mrno_show" id="mr2_mrno_show" value="<?php echo $default ?>" size="15" disabled="disabled" type="text">
   </div>
</div>

<div class="form-row">
  <?php echo label_for('mr2[category]', __($labels['mr2{category}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{category}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{category}')): ?>
    <?php echo form_error('mr2{category}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php
    $categoryDefault = 2;
    if ($mr2->getCategory() != null ) $categoryDefault = $mr2->getCategory(); 
  ?>
  <select name="mr2[category]" id="mr2_category" onchange="changeProject()" disabled>
    <?php foreach (CommonValues::$gMRCategory['key'] as $key=>$category) { ?>
    <option value="<?php echo $category;  if ($category == $categoryDefault) echo '" selected="1'?>"><?php echo $key ?></option>
    <?php } ?>
    </select>
    </div>
</div>
<div id ="project">
<? if ($categoryDefault == CommonValues::$gMRCategory['key']['Project']) {?>
<div class="form-row">
  <?php echo label_for('mr2[project_id]', __($labels['mr2{project_id}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{project_id}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{project_id}')): ?>
    <?php echo form_error('mr2{project_id}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_select_tag($mr2, 'getProjectId', array (
  'related_class' => 'Project',
  'control_name' => 'mr2[project_id]',
  'include_blank' => true,
  'disabled'=>1,
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>
<?} else {?>
<input type="hidden" name = "mr2[project_id]" id="mr2_project_id" value ="0">
<?}?>
</div>

<div class="form-row">
  <?php echo label_for('mr2[reqarrdate]', __($labels['mr2{reqarrdate}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{reqarrdate}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{reqarrdate}')): ?>
    <?php echo form_error('mr2{reqarrdate}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_date_tag($mr2, 'getReqarrdate', array (
  'rich' => true,
  'calendar_button_img' => '/sf/sf_admin/images/date.png',
  'control_name' => 'mr2[reqarrdate]',
  'disabled'=>1,
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>



<div class="form-row">
  <?php echo label_for('mr2[status]', __($labels['mr2{status}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{status}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{status}')): ?>
    <?php echo form_error('mr2{status}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php  $status = $mr2->getStatus()?  $mr2->getStatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRStatus['value'][$status]?>">
  <input type="hidden" name ="mr2[status]" id ="mr2_status" value="<?php echo $status?>">
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr2[approvalstatus]', __($labels['mr2{approvalstatus}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr2{approvalstatus}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr2{approvalstatus}')): ?>
    <?php echo form_error('mr2{approvalstatus}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php  $status = $mr2->getApprovalstatus()?  $mr2->getApprovalstatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRApprovalStatus['value'][$status]?>">
  <input type="hidden" name ="mr2[approvalstatus]" id ="mr2_approvalstatus" value="<?php echo $status?>">
    </div>
</div>


</fieldset>

<!--Tien code here
get information for MR-->
<?php
    if ($mr2->getComponentgroupId()){
        $componentGroupId = $mr2->getComponentgroupId();
        
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID , $componentGroupId);
        $c->addAscendingOrderByColumn(ComponentsPeer::ID);
        
        $componentList = ComponentsPeer::doSelect($c);
    }
?>


<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="25%">Product Code
              </th>
      <th id="sf_admin_list_th_description" width="35%">Description
              </th>
      <th id="sf_admin_list_th_description" width="10%">Brand
              </th>       
      <th id="sf_admin_list_th_description" width="5%">Unit
              </th>
      <th id="sf_admin_list_th_description" width="10%">Expected Delivery Date (YYYY-MM-DD)</th>
      
      <th id="sf_admin_list_th_description">Qty to request</th>
      <th id="sf_admin_list_th_description">Min stock (%)</th>
</tr>
</thead>
<!--show component here-->
<?php if (isset($componentList) && $componentList) {
    foreach ($componentList as $key=>$components) { 
        $component1= ComponentPeer::retrieveByPK($components->getComponentId());
        $c = new Criteria();
        $c->add(WarehousePeer::COMPONENT_ID , $component1->getId());
        $warehouse = WarehousePeer::doSelectOne($c);
        ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><?echo $components->getDate()?></td>
            <td><input type="text" name="qtys[]" id ="qtys" disabled size="5" class="QTYS" onkeyup="calcMinStock()" value ="<?echo $components->getQty1()?>">
            <input type="hidden" name="minStockQtys[]" id ="minStockQtys"  class = "MINSTOCKQTYS" value="<?php echo $component1->getMinstockqty()?>"/>
            <input type="hidden" name="stockQtys[]" id ="stockQtys"  class = "STOCKQTYS" value="<?php  echo $warehouse->getClosing()?>"/>
            </td>
            <td><input type="text" name="minStocks[]" id ="minStocks" class ="MINSTOCKS" size="2" disabled value ="<?echo $components->getQty2()?>"></td>
        </tr>
<?php } }?>
</table>
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_MRSUBSTK&authenticationSub=APPROVE_MRSUBFTR&mod=MRSUB&id='.$mr2->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRSUBSTK~3authenticationSub~4APPROVE_MRSUBFTR~3mod~4MRSUB~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this MR?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_MRSUBSTK&authenticationSub=APPROVE_MRSUBFTR&mod=MRSUB&id='.$mr2->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRSUBSTK~3authenticationSub~4APPROVE_MRSUBFTR~3mod~4MRSUB~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
</div>

</div>
